package chapter.sixth.item35;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.junit.Test;

public class RunTests {
	
	public static void main(String[] args) throws ClassNotFoundException {
		int tests = 0;
		int passed = 0;
		Class testClass = Class.forName(args[0]);
		for(Method m:testClass.getDeclaredMethods()){
			if(m.isAnnotationPresent(Test.class)){
				tests++;
				try{
					m.invoke(null);
					passed++;
				}catch(InvocationTargetException wrappedExc){
					Throwable exc = wrappedExc.getCause();
					System.out.println(m+" failed: "+exc);
				} catch (Exception e) {
					System.out.println("INVALID @Test: "+m);
				}
			}
		}
		System.out.printf("passed: %d,Failed: %d%n",passed,tests-passed);
	}
}
